package com.wbp.cms.core.project.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.wbp.cms.client.project.domain.ProjectProfitDO;
import com.wbp.cms.client.project.service.ProjectProfitService;
import com.wbp.cms.client.result.Result;
import com.wbp.cms.core.project.dao.ProjectProfitDAO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午3:10:05
 */
@Service("projectProfitService")
public class ProjectProfitServiceImpl implements ProjectProfitService {
  
  /**
   * 
   */
  private static final long serialVersionUID = -7650060211922387468L;

  @Resource
  private  ProjectProfitDAO  projectProfitDAO ;

  @Override
  public Result<Long> addProjectProfit(ProjectProfitDO projectProfitDO) {
    Preconditions.checkNotNull(projectProfitDO, "projectProfitDO不能为null") ;
    
    return Result.buildSuccess( projectProfitDAO.insert(projectProfitDO) ) ;
  }

   
  @Override
  public int batchAddProjectProfit(List<ProjectProfitDO> projectProfitList, Long projectId) {
    Preconditions.checkNotNull(projectProfitList, "projectProfitDO不能为null") ;
    Preconditions.checkArgument(projectProfitList.size() > 0 ,  "projectProfitDO.size应>0");
    int count = 0 ;
    for(ProjectProfitDO pp : projectProfitList){
        pp.setProjectId(projectId); 
        this.projectProfitDAO.insert(pp) ;
        count++ ;
    }
    return count ;
  }

   
  @Override
  public Result<Boolean> modifyProjectProfit(ProjectProfitDO projectProfitDO) {
    Preconditions.checkNotNull(projectProfitDO, "projectProfitDO不能为null") ;
    
    return Result.buildSuccess(this.projectProfitDAO.update(projectProfitDO) >0 );
  }

  
  @Override
  public Boolean deleteProjectProfitByProject(Long projectId) {
    Preconditions.checkNotNull(projectId, "projectId不能为null") ;
    Preconditions.checkArgument(projectId > 0, "projectId 应>0 ");
    return  this.projectProfitDAO.deletetByProjectId(projectId) > 0 ;
  }

   
  @Override
  public List<ProjectProfitDO> queryProjectProfitByProject(Long projectId) {
    Preconditions.checkNotNull(projectId, "projectId不能为null") ;
    Preconditions.checkArgument(projectId > 0, "projectId 应>0 ");
    
    return this.projectProfitDAO.queryByProjectId(projectId);
  }

}
